<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%-- 引入页面头 --%>
<%@ include file="/pageHead.jsp"%>
<form name="form1" id="form1"
	action="<%-- ${systemctx}/sample/saveSample.web --%>" method="post">
	<div class="pageMain">
		<div class="pageTitle"><%=MessageResourcesUtils.getMessage(request, "systemmanage.servicemanagement.title") %><span></span><%=MessageResourcesUtils.getMessage(request, "dailyoperation.storechargemanage.title") %><span></span><%=MessageResourcesUtils.getMessage(request, "dailyoperation.storechargemanage.Add") %></div>
		<div class="pageBody">
			<div class="form-group">
				<ul>
					<li>
						<i>*</i>
						<label><%=MessageResourcesUtils.getMessage(request, "dailyoperation.storechargemanage.storecode") %></label>
						<span><input type="text" id="storecode" name="storecode" value="" class="validate[required]"/></span>
					</li>
					<li>
						<i></i> 
						<label><%=MessageResourcesUtils.getMessage(request, "dailyoperation.storechargemanage.storename") %></label>
						<span><input type="text" id="name" name="name" value=""/></span>
					</li>
				</ul>
			
				<ul>
					<li>
						<i>*</i> 
						<label><%=MessageResourcesUtils.getMessage(request, "dailyoperation.services.servicesList.servicenum") %></label>
						<span><input type="text" id="servicenum" name="servicenum" value="" class="validate[required]"/></span>
					</li>
					<li>
						<i></i> 
						<label><%=MessageResourcesUtils.getMessage(request, "dailyoperation.services.servicesList.servicename") %></label>
						<span><input type="text" id="servicename" name="servicename" value=""/></span>
					</li>
				</ul>
				
				<ul>
					<li>
						<i>*</i> 
						<label><%=MessageResourcesUtils.getMessage(request, "dailyoperation.chargemanage.proposed") %></label>
						<span>
							<input type="checkbox" id="isproposedcheck" name="isproposedcheck" class="check-box"/>
						</span>
					</li>
					<li>
						<i>*</i> 
						<label><%=MessageResourcesUtils.getMessage(request, "dailyoperation.chargemanage.proposedprice") %></label>
						<span><input type="text" id="proposedprice" name="proposedprice" value="" class="iss_amount"/></span>
					</li>
				</ul>
				
				<ul>
					<li>
						<i>*</i> 
						<label><%=MessageResourcesUtils.getMessage(request, "dailyoperation.chargemanage.month") %></label>
						<span>
							<input type="checkbox" id="ismonthcheck" name="ismonthcheck" class="check-box"/>
						</span>
					</li>
					<li>
						<i>*</i> 
						<label><%=MessageResourcesUtils.getMessage(request, "dailyoperation.chargemanage.monthprice") %></label>
						<span><input type="text" id="monthprice" name="monthprice" value="" class="iss_amount"/></span>
					</li>
				</ul>
			</div>
			<div class="button-group">
				<input type="hidden" id="isproposed" name="isproposed" value="" />
				<input type="hidden" id="ismonth" name="ismonth" value="" />
				<input type="hidden" id="storeid" name="storeid" value="" />
				<input type="hidden" id="serviceid" name="serviceid" value="" />
				<input type="hidden" id="serviceids" name="serviceids" value="" />
				<input type="button" class="btn btn-default" id="butSave" name="butSave" value="<%=MessageResourcesUtils.getMessage(request, "common.button.save") %>" />
				<input type="button" class="btn btn-default"  id="butReturn" name="butReturn" value='<%=MessageResourcesUtils.getMessage(request, "common.button.back") %>' />
				
			</div>
		</div>
	</div>
</form>
<script type="text/javascript">
	$(document).ready(function(){
		var proposedprice_amount = '';
		var monthprice_amount = '';
		
		$('#proposedprice').blur(function(){
			proposedprice_amount = $('#proposedprice').val()
		})
		
		$('#monthprice').blur(function(){
			monthprice_amount = $('#monthprice').val();
		})
		
		$("#storecode").issNewMagnifier({
			title: '<%=MessageResourcesUtils.getMessage(request, "systemmanage.databasebinding.storemagnifiertitle") %>',
			url: '${systemctx}/publicMagnifier/publicMagnifier.json',
			sortName : 'modifytime',
			sortOrder : 'desc',
			linkName: 'number',
			callSqlKey: 'queryStoreMagnifierSql',
			changeIgnore: ['storecode'],
			columns: [[
					{title:'<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.number") %>', field:'number', width:180, sortable:true, align: 'left',formel:'storecode'},
					{title:'<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.name") %>', field:'name', sortable:true, align: 'left', formel:'name'},
					{field:'id',hidden:true,formel:'storeid'}
			]],
			onBeforeOpen:function(p){
		      var queryParams = {
		    		  querystore: '%' + $("#storecode").val() + '%',
		    		  statusid: <%=SysConstant.RecordStatus.VALID %>,
		    		  state : <%=SysConstant.CommonApproveStatus.OK %>
		      };
		      return queryParams;
		    }
		});
		
		$("#servicenum").issNewMagnifier({
			title: '<%=MessageResourcesUtils.getMessage(request, "dailyoperation.storechargemanage.fangdajing") %>',
			url: '${systemctx}/publicMagnifier/publicMagnifier.json',
			sortName : 'modifytime',
			sortOrder : 'desc',
			linkName: 'servicenum',
			callSqlKey: 'queryServicesMagnifierSql',
			changeIgnore: ['servicenum'],
			columns: [[
					{title:'<%=MessageResourcesUtils.getMessage(request, "dailyoperation.services.servicesList.servicenum") %>', field:'servicenum', width:180, sortable:true, align: 'left',formel:'servicenum'},
					{title:'<%=MessageResourcesUtils.getMessage(request, "dailyoperation.services.servicesList.servicename") %>', field:'servicename', sortable:true, align: 'left', formel:'servicename'},
					{field:'id',hidden:true,formel:'serviceid'}
					
			]],
			onBeforeOpen:function(p){
		      var queryParams = {
		    		  statusid:<%=SysConstant.RecordStatus.VALID %>,
		    		  checkstatus:<%=SysConstant.CheckStatus.CHECKED %>,
		    		  queryservicenum:'%'+$('#servicenum').val()+'%'
		      };
		      return queryParams;
		    }
		});
			
		$("#butReturn").click(function(){
			parent.document.location.reload();
			$.fn.closeIssWindow();
		});
		
		$("#servicenum").blur(function(){
			var servicenum = $("#servicenum").val();
			if(servicenum == ''){
				$('#ismonthcheck').prop("checked",false);
				$('#isproposedcheck').prop("checked",false);
				$('#proposedprice').val('');
				$('#monthprice').val('');
			}
		});
		
		$('#isproposedcheck').change(function(){
			//如果选中，也填写，则赋值
			if($("#isproposedcheck").prop("checked")){
				$('#isproposed').val('1');
			}else{
				$('#isproposed').val('');
				$('#proposedprice').val('');
				proposedprice_amount = '';
			}
		})
		
		$('#ismonthcheck').change(function(){
			//如果选中，也填写，则赋值
			if($("#ismonthcheck").prop("checked")){
				$('#ismonth').val('1');
			}else{
				$('#ismonth').val('');
				$('#monthprice').val('')
				monthprice_amount = '';
			}
		})
		
		$('#butSave').click(function() {
				var storeid = $('#storeid').val();
				var serviceid = $('#serviceid').val();
				if(storeid == ''){
					alert('<%=MessageResourcesUtils.getMessage(request,"alertinfo.chargemanage.Add.alert7")%>')
					return;
				}
				if(serviceid == ''){
					alert('<%=MessageResourcesUtils.getMessage(request,"alertinfo.chargemanage.Add.alert8")%>')
					return;
				}
				
				//如果 两个单选框都不选择的话，就提示
				if(!($("#isproposedcheck").prop("checked")) && !($("#ismonthcheck").prop("checked"))){
					alert('<%=MessageResourcesUtils.getMessage(request,"alertinfo.chargemanage.Add.alert")%>');
					return;
				}
				 
				var proposedprice = proposedprice_amount;
				var monthprice = monthprice_amount;
				//如果只选中单选框，但不填写价格，就提示
				if($("#isproposedcheck").prop("checked") && proposedprice ==''){
					alert('<%=MessageResourcesUtils.getMessage(request,"alertinfo.chargemanage.Add.alert1")%>');
					return;
				}else if(!$("#isproposedcheck").prop("checked") && proposedprice !=''){
					alert('<%=MessageResourcesUtils.getMessage(request,"alertinfo.chargemanage.Add.alert3")%>');
					return;
				}else if($("#ismonthcheck").prop("checked") && monthprice == ''){
					alert('<%=MessageResourcesUtils.getMessage(request,"alertinfo.chargemanage.Add.alert2")%>');
					return;
				}else if(!$("#ismonthcheck").prop("checked") && monthprice != ''){
					alert('<%=MessageResourcesUtils.getMessage(request,"alertinfo.chargemanage.Add.alert4")%>');
					return;
				}
				
				if(proposedprice =='0'){
					alert('<%=MessageResourcesUtils.getMessage(request,"alertinfo.chargemanage.Add.alert5")%>');
					return;
				}
				if(monthprice == '0'){
					alert('<%=MessageResourcesUtils.getMessage(request,"alertinfo.chargemanage.Add.alert6")%>');
					return;
				}
				
				if(confirm('<%=MessageResourcesUtils.getMessage(request,"alertinfo.common.jsp.alert1")%>') ){
					showSending();
					$.ajax({
						type: 'POST',
					    url: '${systemctx}/dailyoperation/services/validattionStoreChargeManage.json',
					    data: $("#form1").serialize(),
					    dataType: 'json',
					    success: function(data)
					    {
					    	//关闭执行...
							closeSending();
					    	if (data.messagetype == '2')
					    	{
					    		//显示AJAX请求后的提示信息
								$.fn.ajaxmessage(data);
					    	}
					    	else
					    	{
								showSending();
								form1.action="${systemctx}/dailyoperation/storechargemanage/addStoreChargeManage.web?proposedprice="+proposedprice+"&monthprice="+monthprice;
								form1.submit();
					    	}
					    }
					});
			}
		});
	});
</script>
<%-- 引入页面尾 --%>
<%@ include file="/pageFloor.jsp"%>